#include"Protocol.hpp"
#include"Socket.hpp"
#include"Tcpserve.hpp"
#include"NetCal.hpp"
#include<memory>
#include"Daemon.hpp"
using namespace SocketModule;

void Usage(std::string proc)
{
    std::cerr<<"启动错误："<<proc<<"  "<<"port"<<std::endl;
}

int main(int argv,char* argc[])
{
    if(argv!=2)
    {
        Usage(argc[0]);
        exit(USAGE_ERR);
    }
    //s守护进程
    Daemon();
    Enable_File_Log_Strategy();
    //顶层业务层
    std::shared_ptr<Cal> cal=std::make_shared<Cal>();
    //协议层
    std::unique_ptr<Protocol> protocol=std::make_unique<Protocol>([&cal](Request req)->Response{
        return cal->Execute(req);
    });
    //服务器层
    std::unique_ptr<Tcpserve> tsvr=std::make_unique<Tcpserve>(std::stoi(argc[1]),[&protocol](std::shared_ptr<Socket> sock,InetAddr client){
        protocol->GetRequest(sock,client);
    });
    tsvr->Start();

    // uint16_t port=std::stoi(argc[2]);
    // tcpsk->BulidListenSocketMethod(port);
    return 0;
}
